package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.SysUser;
import com.example.demo.mapper.SysUserMapper;
import com.example.demo.service.SysUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    @Override
    public IPage<SysUser> getByPage(Integer pageNum, Integer pageSize, SysUser params) {
        Page<SysUser> page = new Page<>(pageNum, pageSize);
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .like(StringUtils.hasText(params.getUserName()), SysUser::getUserName, params.getUserName())
                .like(StringUtils.hasText(params.getNickName()), SysUser::getNickName, params.getNickName())
                .eq(StringUtils.hasText(params.getStatus()), SysUser::getStatus, params.getStatus());
        IPage<SysUser> result = baseMapper.selectPage(page, queryWrapper);
        return result;
    }

}